package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.GroupCompanyAddDTO;
import org.jsola.hr.dto.GroupCompanyUpdateDTO;
import org.jsola.hr.entity.GroupCompanyDO;
import org.jsola.hr.query.GroupCompanyQuery;
import org.jsola.hr.service.IGroupCompanyService;
import org.jsola.hr.vo.GroupCompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 子公司分管公司关系表
 *
 * @author zhr
 */
@Component
public class GroupCompanyTestHelper extends BaseTestHelper {
    
    @Autowired
    private IGroupCompanyService groupCompanyService;

    /**
     * 生成add测试数据
     * @return GroupCompanyAddDTO
     */
    public GroupCompanyAddDTO getGroupCompanyAddDTO(){
        GroupCompanyAddDTO groupCompanyAddDTO = new GroupCompanyAddDTO();
        groupCompanyAddDTO.setGroupId(getRandomValue("varchar",32));
        groupCompanyAddDTO.setCompanyId(getRandomValue("varchar",32));
        groupCompanyAddDTO.setIsAll(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return groupCompanyAddDTO;
    }


    /**
     * 生成update测试数据
     * @return GroupCompanyUpdateDTO
     */
    public GroupCompanyUpdateDTO getGroupCompanyUpdateDTO(GroupCompanyVO groupCompanyVO){
        return groupCompanyService.selectDOById(groupCompanyVO.getId(), SITE_ID).to(GroupCompanyUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return GroupCompanyQuery
     */
    public GroupCompanyQuery getGroupCompanyQuery() {
        GroupCompanyQuery groupCompanyQuery = new GroupCompanyQuery();
        List<GroupCompanyDO> groupCompanyDOList = groupCompanyService.list(new GroupCompanyDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(groupCompanyDOList)) {
            GroupCompanyDO groupCompanyDO = groupCompanyDOList.get(0);
            groupCompanyQuery = groupCompanyDO.to(GroupCompanyQuery.class);
        }
        return groupCompanyQuery;
    }

    /**
     * 保存示例
     * @return GroupCompanyVO
     */
    public GroupCompanyVO saveGroupCompanyExample(){
        GroupCompanyAddDTO addDTO = this.getGroupCompanyAddDTO();
        GroupCompanyVO groupCompanyVO = groupCompanyService.save(addDTO,buildTokenUser());
        return groupCompanyVO;
    }


}

